package com.potenza.training.dictionary.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.potenza.training.dictionary.dao.ProjectTypeDao;
import com.potenza.training.dictionary.entity.ProjectType;
import com.potenza.training.dictionary.server.ProjectTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("projectTypeServiceImpl")
public class ProjectTypeServiceImpl extends ServiceImpl<ProjectTypeDao, ProjectType> implements ProjectTypeService {

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ProjectTypeDao projectTypeDao;

    @Override
    public List<ProjectType> findAll() {
        Object projectType = redisTemplate.opsForValue().get("projectType");
        if (projectType==null){
            List<ProjectType> list = this.list();
            redisTemplate.opsForValue().set("projectType", list);
            return list;
        }

        return (List<ProjectType>)projectType;
    }

}